package com.flymobi.playmobile.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.flymobi.po.Users;
import com.flymobi.util.C;
import com.flymobi.util.JsonHttpClient;

public class UsersService extends IService {
	public static List<Map<String, Object>> cache;

	public static Users login(String name, String pwd) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("act", C.Act.Users_login);
		params.put("name", name);
		params.put("pwd", pwd);
		JSONArray ja = JsonHttpClient.post(params);
		if (ja == null) {
			return null;
		}
		int size = ja.length();
		for (int i = 0; i < size; i++) {
			JSONObject jo;
			try {
				jo = ja.getJSONObject(i);
				jo = jo.getJSONObject("users");
				Users u = new Users();
				u.setId(jo.getLong("id"));
				u.setName(jo.getString("name"));
				u.setPwd(jo.getString("pwd"));
				return u;
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
}
